<%@ page import="ro.gateway.aida.usr.*,
                 ro.gateway.aida.srv.EditorServlet,
                 java.util.Properties,
                 java.util.Locale,
                 ro.xblue.translator.*,
                 ro.gateway.aida.obj.db.AIDALocationDB,
                 ro.gateway.aida.obj.db.LanguageDB,
                 ro.gateway.aida.db.PersistenceToken,
                 ro.gateway.aida.db.PersistenceManager,
                 ro.gateway.aida.utils.Utils,
                 ro.gateway.aida.obj.Country"  %>

<%@ page import="java.util.Hashtable"  %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@ taglib uri="/WEB-INF/translator.tld" prefix="trans" %>

<trans:initPage module="users" />

<%
			Utils.setBreadCrumbs(request,"bc.users.edit");
	// test cvs
      Hashtable bean = (Hashtable) request.getAttribute(EditUserServlet.PNAME_BEAN);

      if (bean == null) {

            response.sendError(HttpServletResponse.SC_NOT_FOUND);

            return;

      }

      String key = (String) bean.get(EditUserServlet.PNAME_KEY);

      String action = (String) bean.get(EditUserServlet.PNAME_ACTION);

      String ctx = request.getContextPath();

      // edit/delete/new

      String editing_action = (String) bean.get(EditUserServlet.PNAME_ACTION);



      String wtd = "act.save";

      if (EditUserServlet.PV_ACTION_DELETE.equals(editing_action)) {

            wtd = "act.delete";

      } else if (EditUserServlet.PV_ACTION_NEW.equals(editing_action)) {

            wtd = "act.save";

      }



      String ESTR = "";

      User user = (User) bean.get(EditUserServlet.PNAME_USER);

      String firstNames = user.getFirstNames();if (firstNames == null) firstNames = ESTR;

      String lastName = user.getLastName();if (lastName == null) lastName = ESTR;

      String login = user.getLogin();if (login == null) login = ESTR;

	  String org = user.getOrganization();if (org == null) org = ESTR;

      String email = user.getEmail();if (email == null) email = ESTR;
      PersistenceToken token = PersistenceManager.tokenLookup( application );
	  String defaultLang=LanguageDB.getManager(token ).getDefault();
	  
      String wlang = user.getWorkingLanguage(); if (wlang == null) wlang = defaultLang;

      Translator translator = (Translator) application.

            getAttribute(TranslatorConstants.BLUE_TRANSLATOR);

      Translator_DB translator_db = ( Translator_DB ) application.

            getAttribute(TranslatorConstants.DB_TRANSLATOR);



      Object screen = request.getAttribute(EditUserServlet.PNAME_SCREEN);

      String[] errors = (String[]) request.getAttribute(EditUserServlet.PNAME_ERRORS);


      
      User logged_user = UserUtils.getLogged(request);
      Arbiter ar = Arbiter.getManager(token );
%>

<html>



<head>

<% if (EditUserServlet.PV_ACTION_REGISTER.equals(action)) { %>

    <title><trans:showPageMessage label="page.regtitle" /></title>

<% } else { %>

    <title><trans:showPageMessage label="page.title" /></title>

<% } %>

<link rel="stylesheet" href="<%=ctx%>/alf.css" type="text/css">

</head>



<body>


   <% pageContext.include("../header.jsp"); %>

<table align="center" width="75%" border="0" cellspacing="1" cellpadding="5" background=<%=ctx%>/images/pixelbgtable.gif class="text_search">

  <% if (EditUserServlet.PV_ACTION_REGISTER.equals(action)) { %>
<tr>

    <td colspan="2" class="textalb"> <trans:showPageMessage label="page.title1" /> </td>

  </tr>
  <tr bgcolor="#FFFFFF">

    <td colspan="2"> <trans:showPageMessage label="page.regintro" /> </td>

  </tr>

  <% } else { %>

  <tr background=<%=ctx%>/images/pixelbgtable.gif>

    <td colspan="2" class="textalb"> <trans:showMessage module="admin" label="page.pagename" />

      :: <trans:showMessage module="admin" label="page.modusr" /> </td>

  </tr>

  <% } %>

  <% if (EditUserServlet.PV_SCR_EDIT.equals(screen)) { %>

  <script language="javascript">

    function submit_theform(action) {

        document.theform.sbutton.disabled=1;

        document.theform.cbutton.disabled=1;

        document.theform.action.value=action;

        document.theform.submit();

    }

</script>

  <form method="POST" action="<%=ctx%>/usr/uedit" name="theform">

    <input type="hidden" name="<%=EditorServlet.PNAME_KEY%>" value="<%=key%>" />

    <input type="hidden" name="<%=EditorServlet.PNAME_ACTION%>" value="<%=EditorServlet.PV_ACTION_EDIT%>" />

    <% if (errors != null) { %>

    <tr bgcolor="#FFFFFF">

      <td colspan="2" class=text> <font color="#CC0000"><b><trans:showPageMessage label="form.errors" /></b>:<br>

        <br>

        <% for (int i = 0; i < errors.length; i++) { %>

        <trans:showPageMessage label='<%=errors[i]%>' /><br>

        <% } %>
</font>
    </tr>

    <tr bgcolor="#FFFFFF"> </td>

    <% } %>

    <tr bgcolor="#FFFFFF">

      <td align="right" width="30%" class="text_searchBold"><trans:showPageMessage label="page.fnames" />:</td>

      <td>

        <input type="text" name="firstnames" value="<%=firstNames%>" onkeydown="textCounter(this.form.firstnames,this.form.cfirstnames,200);" onkeyup="textCounter(this.form.firstnames,this.form.cfirstnames,200);"/>
<input readonly type="text" name="cfirstnames" size="3" maxlength="4" value=""> <trans:showPageMessage label="charactersleft" />
      </td>

    </tr>

    <tr bgcolor="#FFFFFF">

      <td align="right" width="30%" class="text_searchBold"><trans:showPageMessage label="page.lname" />:</td>

      <td>

        <input type="text" name="lastname" value="<%=lastName%>" onkeydown="textCounter(this.form.lastname,this.form.clastname,200);" onkeyup="textCounter(this.form.lastname,this.form.clastname,200);"/>
<input readonly type="text" name="clastname" size="3" maxlength="4" value=""> <trans:showPageMessage label="charactersleft" />
      </td>

    </tr>

    <tr bgcolor="#FFFFFF">

      <td align="right" width="30%" class="text_searchBold"><trans:showPageMessage label="page.email" />(*):</td>

      <td>

        <input type="text" name="email" value="<%=email%>" onkeydown="textCounter(this.form.email,this.form.cemail,100);" onkeyup="textCounter(this.form.email,this.form.cemail,100);"/> 
<input readonly type="text" name="cemail" size="3" maxlength="4" value=""> <trans:showPageMessage label="charactersleft" />
      </td>

    </tr>

    <tr bgcolor="#FFFFFF">

      <td align="right" width="30%" class="text_searchBold"><trans:showPageMessage label="page.login" />(*):</td>

      <td>

        <input type="text" name="login" value="<%=login%>" onkeydown="textCounter(this.form.login,this.form.clogin,100);" onkeyup="textCounter(this.form.login,this.form.clogin,100);"/> 
<input readonly type="text" name="clogin" size="3" maxlength="4" value=""> <trans:showPageMessage label="charactersleft" />
      </td>
<tr bgcolor="#FFFFFF">

      <td align="right" width="30%" class="text_searchBold"><trans:showPageMessage label="page.org" />:</td>

      <td>

        <input type="text" name="organization" value="<%=org%>" onkeydown="textCounter(this.form.organization,this.form.corganization,200);" onkeyup="textCounter(this.form.organization,this.form.corganization,200);"/> 
		<input readonly type="text" name="corganization" size="3" maxlength="4" value=""> <trans:showPageMessage label="charactersleft" />

      </td>
    </tr>

    <tr bgcolor="#FFFFFF">

      <td valign="top" align="right" width="30%" class="text_searchBold"><trans:showPageMessage label="form.pass" />(*):</td>

      <td>

        <input type="password" name="pass" value="" onkeydown="textCounter(this.form.pass,this.form.cpass,100);" onkeyup="textCounter(this.form.pass,this.form.cpass,100);"/>

        ** <input readonly type="text" name="cpass" size="3" maxlength="4" value=""> <trans:showPageMessage label="charactersleft" /><br>

        <br>

        <trans:showPageMessage label="form.repass" /><br>

        <input type="password" name="repass" value="" onkeydown="textCounter(this.form.repass,this.form.crepass,100);" onkeyup="textCounter(this.form.repass,this.form.crepass,100);"/>

        ** <input readonly type="text" name="crepass" size="3" maxlength="4" value=""> <trans:showPageMessage label="charactersleft" /><br>

        <% if (user.getPass() != null) { %>

        <br>

        ** : <trans:showPageMessage label="form.passhint" /> </td>

        <% } %>

    </tr>
    <tr bgcolor="#FFFFFF">

      <td align="right" width="30%" class="text_searchBold"><trans:showPageMessage label="page.wlang" />:</td>

      <td>

        <select name="wlang">

            <%

        LanguageBean[] langs = (LanguageBean[]) application.

        getAttribute(TranslatorConstants.BLUE_AVAIL_LANGS);

        LanguageBean clang = TranslatorUtils.getCurrentLanguage(request, application);

            %>

            <% for (int i = 0; i < langs.length; i++) { %>

            <%

        String disp_lang = translator != null ?

              translator.getMessage(clang.language, "translator", "lng.avail." + langs[i].language) :

              translator_db != null ? translator_db.getMessage(clang.language, "translator", "lng.avail." + langs[i].language) : langs[i].language;

        if (disp_lang == null) {

              disp_lang = langs[i].locale.getDisplayLanguage();

        }

            %>

          <option <%=(langs[i].language.equals(wlang)) ? "selected='true' " : ""%>value="<%=langs[i].language%>"><%=disp_lang%></option>

          <% } %>

        </select>

      </td>

    </tr>

    <tr bgcolor="#FFFFFF">

      <td align="right" width="30%" class="text_searchBold"><trans:showPageMessage label="page.usercountry" />:</td>

      <td>

        <select name="ucountry">
        <%
        Country[] countries = AIDALocationDB.getManager(token ).getAllCountries();
        %>
        <option value=""><trans:showPageMessage label="page.selcntry" /></option>
        <% if (countries != null) for (int i = 0; i < countries.length; i++) { %>
        <option <%=countries[i].getIso3().equals(user.getCountry_iso3()) ? "selected=\"true\"" : "" %> value="<%=countries[i].getIso3()%>"><%=countries[i].getName()%></option>
        <% } %>
        </select>

      </td>

    </tr>

    <% if (!EditUserServlet.PV_ACTION_REGISTER.equals(action)) { %>
    <% if ( ar.canDo( request, Perms.ADMIN_TOOLS ) ) { %>
    <tr bgcolor="#FFFFFF">
      <td align="right" width="30%" class="text_searchbold"><trans:showPageMessage label="page.lstandby" />:</td>
      <td class="text_searchbold">
        <input <%=user.isStandby() ? "checked=\"true\" " : ""%> 	type="checkbox" name="standby" value="1" />
        <trans:showPageMessage label="page.standby" />
	</td>
    </tr>
    <% } %>
    <% } %>

	<tr bgcolor="#FFFFFF">
		<td colspan="2">
			<input name="sbutton" type="button" class="butonsave" value="<trans:showPageMessage label="form.bsave" hide_link="true" />" onclick="javascript:submit_theform('<%=EditorServlet.PV_ACTION_CONFIRM%>');">
			<input name="cbutton" type="button" class="butonsave" value="<trans:showPageMessage label="form.bcancel" hide_link="true" />" onclick="javascript:submit_theform('<%=EditorServlet.PV_ACTION_CANCEL%>');">
		</td>
	</tr>
  </form>

  <% } else if (EditUserServlet.PV_SCR_CONFIRM.equals(screen)) { %>

  <script language="javascript">

    function submit_theform(action) {

        document.theform.sbutton.disabled=1;

        document.theform.cbutton.disabled=1;

        if (document.theform.bbutton) {

            document.theform.bbutton.disabled=1;

        }

        document.theform.action.value=action;

        document.theform.submit();

    }

</script>

  <form method="POST" action="<%=ctx%>/usr/uedit" name="theform">

    <input type="hidden" name="<%=EditorServlet.PNAME_KEY%>" value="<%=key%>" />

    <input type="hidden" name="<%=EditorServlet.PNAME_ACTION%>" value="<%=EditorServlet.PV_ACTION_EDIT%>" />

    <tr bgcolor="#FFFFFF">

      <td colspan="2"><trans:showPageMessage label="page.confscr" /></td>

    </tr>

    <tr bgcolor="#FFFFFF">

      <td width="30%" align="right" class="text_searchBold"><trans:showPageMessage label="page.fnames" />:</td>

      <td><%=firstNames%></td>

    </tr>

    <tr bgcolor="#FFFFFF">

      <td width="30%" align="right" class="text_searchBold"><trans:showPageMessage label="page.lname" />:</td>

      <td><%=lastName%></td>

    </tr>

    <tr bgcolor="#FFFFFF">

      <td width="30%" align="right" class="text_searchBold"><trans:showPageMessage label="page.email" />:</td>

      <td><%=email%></td>

    </tr>

    <tr bgcolor="#FFFFFF">

      <td width="30%" align="right" class="text_searchBold"><trans:showPageMessage label="page.login" />:</td>

      <td><%=login%></td>

    </tr>
<tr bgcolor="#FFFFFF">

      <td width="30%" align="right" class="text_searchBold"><trans:showPageMessage label="page.org" />:</td>

      <td><%=org%></td>

    </tr>
    <tr bgcolor="#FFFFFF">

      <td width="30%" align="right" class="text_searchBold"><trans:showPageMessage label="page.wlang" />:</td>

      <td><%=new Locale(wlang).getDisplayLanguage()%></td>

    </tr>

    <% if (!EditUserServlet.PV_ACTION_REGISTER.equals(action)) { %>

    <tr bgcolor="#FFFFFF">

      <td width="30%" align="right" class="text_searchbold"><trans:showPageMessage label="page.lstandby" />:</td>

      <td class="text_searchbold">

        <input disabled="true" <%=user.isStandby() ? "checked=\"true\" " : ""%>type="checkbox" name="standby" value="1">

        <trans:showPageMessage label="page.standby" /> </td>

    </tr>

    <% } %>

    <tr bgcolor="#FFFFFF">

      <td colspan="2">

        <% if (!EditUserServlet.PV_ACTION_DELETE.equals(editing_action)) { %>
<input name="bbutton" type="button" class="butonsave" value="<trans:showPageMessage label="form.bback" hide_link="true" />" onclick="javascript:submit_theform('<%=EditorServlet.PV_ACTION_EDIT%>');"><% } %>
        <input name="sbutton" type="button" class="butonsave" value="<trans:showPageMessage label="form.bconfirm" hide_link="true" /> <trans:showPageMessage label='<%=wtd%>' />" onclick="javascript:submit_theform('<%=EditorServlet.PV_ACTION_SAVE%>');">
        <input name="cbutton" type="button" class="butonsave" value="<trans:showPageMessage label="form.bcancel" hide_link="true" />" onclick="javascript:submit_theform('<%=EditorServlet.PV_ACTION_CANCEL%>');">
      </td>

    </tr>

  </form>

  <% } else if (EditUserServlet.PV_SCR_ERROR.equals(screen)) { %>

  <form method="POST" action="<%=ctx%>/usr/uedit" name="theform">

    <input type="hidden" name="<%=EditorServlet.PNAME_KEY%>" value="<%=key%>" />

    <input type="hidden" name="<%=EditorServlet.PNAME_ACTION%>" value="<%=EditorServlet.PV_ACTION_EDIT%>" />

    <% if (errors != null) { %>

    <tr bgcolor="#FFFFFF">

      <td colspan="2"> <trans:showPageMessage label="form.errors" />:

        <% for (int i = 0; i < errors.length; i++) { %>

        <%=errors[i]%>

        <% } %>

    </tr>

    <tr bgcolor="#FFFFFF"> </td>

    <% } %>

    <tr bgcolor="#FFFFFF">

      <td colspan="2">

        <% if (!EditUserServlet.PV_ACTION_DELETE.equals(editing_action)) { %>

        <input name="sbutton" type="submit" value="<trans:showPageMessage label="form.backtoeditor" hide_link="true" />" onclick="javascript:submit_theform('<%=EditorServlet.PV_ACTION_EDIT%>');" class="butonsave">

        <% } %>

        <input name="sbutton" type="submit" value="<trans:showPageMessage label="form.confirm" hide_link="true" /> <trans:showPageMessage label='<%=wtd%>' hide_link="true" />" onclick="javascript:submit_theform('<%=EditorServlet.PV_ACTION_SAVE%>');" class="butonsave">

        <input name="cbutton" type="submit" value="<trans:showPageMessage label="form.cancel" hide_link="true" />" onclick="javascript:submit_theform('<%=EditorServlet.PV_ACTION_CANCEL%>');" class="butonsave">

      </td>

    </tr>

  </form>

  <% } else { %>

  no screen defined: <%=screen%>

  <% } %>

</table>

<trans:showPageMessage label="translator.showhiddentags"/>
<script type="text/javascript" src="<html:rewrite page='/javascript/textCounter.js'/>"></script>
<br>

<br>

   <% pageContext.include("../footer.jsp"); %>

</body>

</html>